package common

import (
	btoml "github.com/BurntSushi/toml"
)

var (
	MysqlCfg  MysqlConfigs
	RedisCfg  RedisConfigs
	AppConCfg AppConfigs
	JwtCfg    JwtConfig
	ArcCfg    ArcConfig
	MailCfg   MailConfig
)

func InitConfig() {
	// 数据库配置
	mc, err := ReadConf("./common/config.toml")
	if err != nil {
		println(err)
	}
	AppConCfg = mc.App
	RedisCfg = mc.Redis
	MysqlCfg = mc.Mysql
	JwtCfg = mc.Jwt
	ArcCfg = mc.Arc
	MailCfg = mc.Mail
}

func ReadConf(filename string) (Config, error) {
	var (
		conf Config
		err  error
	)
	if _, err = btoml.DecodeFile(filename, &conf); err != nil {
		panic(err)
	}
	return conf, err
}
